package com.bds.wm.action;

import com.alibaba.fastjson.JSONObject;
import com.bds.wm.model.common.Result;
import com.bds.wm.model.view.CityNameView;
import com.bds.wm.model.view.CityTierName;
import com.bds.wm.model.view.CityView;
import com.bds.wm.model.view.YearMonth;
import com.bds.wm.service.ViewService;
import com.bds.wm.utils.CheckParams;
import com.bds.wm.utils.Const;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * Created by guoyu on 2018/5/21.
 */
@Controller
public class ViewAction extends BaseAction {
    private static Logger LOGGER = Logger.getLogger(ViewAction.class);

    @Resource
    private ViewService viewService;

    @RequestMapping(value = "/service/view/get_city_tier", method = RequestMethod.GET)
    @ResponseBody
    public Result getCityTier(HttpServletRequest httpRequest, HttpServletResponse httpResponse) {
        Result result = new Result();
        List<CityView> cityViewList = viewService.getCityTier();
        result.setResult(Const.SUC, cityViewList);

        return result;
    }


    @RequestMapping(value = "/service/view/get_city_name", method = RequestMethod.GET)
    @ResponseBody
    public Result getCityName() {
        Result result = new Result();
        List<CityNameView> list = viewService.getCityName();
        result.setResult(Const.SUC, list);
        return result;
    }

    //获取城市级别与城市的级联关系
    @RequestMapping(value = "/service/view/get_city_tier_name", method = RequestMethod.GET)
    @ResponseBody
    public Result getCityTierName() {
        Result result = new Result();
        JSONObject jsonObject = viewService.getCityTierName();
        result.setResult(Const.SUC, jsonObject);
        return result;
    }

    //获取有数据的最新月份
    @RequestMapping(value = "/service/view/get_latest_month", method = RequestMethod.GET)
    @ResponseBody
    public Result getLatestMonth() {
        Result result = new Result();
        YearMonth yearMonth = viewService.getLatestMonth();
        result.setResult(Const.SUC, yearMonth);
        return result;
    }

    //获取品牌品类级联关系
    @RequestMapping(value = "/service/view/get_top_subcate_brand_name", method = RequestMethod.GET)
    @ResponseBody
    public Result getTopSubcateBrandName() {
        Result result = new Result();
        JSONObject jsonObject = viewService.getTopSubcateBrandName();
        result.setResult(Const.SUC, jsonObject);
        return result;
    }
}
